(function(){
	'use strict';
	angular.module('controllers.workOrderData.problemMgmt')
	.controller('ProblemTrendController',ProblemTrendController);
	function ProblemTrendController($scope,workOrderDataService,PublicFn,CoreLoading,$timeout,problemTrendFactory,COREDATA){
		$scope.flag = {
			state: true,
			show: 'view',
			arrow: false
		};
		$scope.sendData = workOrderDataService.getSendData('3');

		//导出路径
		$scope.formPrefix = COREDATA.FORMPREFIX+'workOrderData/problemTrend/export';

		var myEcharts = echarts.init(document.getElementById('doc'));
		$scope.search = function(){
			$scope.flag.state = !$scope.flag.state;
			var timeTitle,option;
			if(!$scope.flag.state){
				$scope.send = workOrderDataService.fmtSendData($scope.sendData);
				timeTitle = PublicFn.fmtDateTitle($scope.send,'timeType');
				problemTrendFactory.query($scope.send,function(res){
					if(res.state === '10000' && res.data.length >=1){
						myEcharts.clear();
						$scope.send.title = timeTitle + '各系统趋势分析所占比率趋势';
						$scope.items = workOrderDataService.getArrayData(res.data);
						$scope.arrs = res.data;
						option = workOrderDataService.getEchartsLineData($scope.items,res.data,$scope.send.title,'percentage');
						option.grid = {
							x2:148
						};
						option.tooltip.formatter = workOrderDataService.getFormatterFn('%');
						option.yAxis[0] = workOrderDataService.formatterYAxis('','{value}%');
						option.dataZoom = {
							show: true,
							realtime: true
						};
						myEcharts.setOption(option);
						$scope.outData = workOrderDataService.exportView(myEcharts,$scope.send);
						$scope.flag.arrow = true;
						$scope.flag.show = 'view';
					}else if(res.data.length === 0){
						workOrderDataService.queryNoDataOrError($scope.flag,'查询无数据');
					}else {
						workOrderDataService.queryNoDataOrError($scope.flag,'查询错误');
					}
					CoreLoading.setState(false);
				});
			}
		};
		$scope.search();

		//监控页面时间，如果时间出错，则查询按钮禁止
		$scope.$watch('myForm.$invalid', function(newValue) {
			newValue ? $scope.flag.arrow = false : $scope.flag.arrow = true;
		});
	}
	ProblemTrendController.$inject = ['$scope','workOrderDataService','PublicFn','CoreLoading','$timeout','problemTrendFactory','COREDATA'];
})();